<?php

namespace Logic;

use Lib\Logger;
use Lib\Config;
use Lib\RedisDriver;

class Factory
{
    protected static $db;
    protected static $log_error;
    protected static $log_scripts;
    protected static $log_sql;

    static function getDb(){
        if(!isset(self::$db)){
            $conf = array_values(Config::$mysql_config);
            self::$db = new \MysqliDb(...$conf);
        }

        return self::$db;
    }

    static function getLogger($name = 'scripts'){
        if($name == 'scripts' || !$name){
            if(!isset(self::$log_scripts)){
                self::$log_scripts = new Logger('scripts');
            }
            return self::$log_scripts;
        }elseif($name == 'error'){
            if(!isset(self::$log_error)){
                self::$log_error = new Logger('error');
            }
            return self::$log_error;
        }elseif($name == 'sql'){
            if(!isset(self::$log_sql)){
                self::$log_sql = new Logger('sql');
            }
            return self::$log_sql;
        }
    }

    static function getPlayerRedis($i){
        return new RedisDriver($i);
    }
}